package main

/*
#include "ThostFtdcUserApiStruct.h"
*/
import "C"
import (
	"CTP/tradeapi"
	"fmt"
	"os"
	"os/signal"
	"time"
)

func main() {
	//"log"
	//"net/http"
	//_ "net/http/pprof"
	//go func() {
	//	log.Println(http.ListenAndServe("localhost:6060", nil))
	//}()
	md := tradeapi.NewTradeapi()

	md.Reg_OnFrontConnectedTradeGo()
	md.Reg_OnFrontDisconnectedTradeGo()
	md.Reg_OnHeartBeatWarningTradeGo()
	md.Reg_OnRspUserLoginTradeGo()
	md.Reg_OnRspAuthenticateTradeGo()

	//defer md.FreeMdapi()
	md.ConnectTradeGo("E:\\godev\\ctptest2\\", "tcp://180.168.146.187:10100")
	//md.ConnectTradeGo("\\", "tcp://180.168.146.187:10130")
	md.InitTradeGo()
	//md.JoinTradeGo()
	time.Sleep(time.Duration(2) * time.Second)
	md.SendAuthGo()
	time.Sleep(time.Duration(2) * time.Second)
	loginfield := tradeapi.CThostFtdcReqUserLoginFieldgo{BrokerID: "9999", UserID: "xxxx", Password: "xxxxx"}
	md.LoginTradego(loginfield, 0)
	time.Sleep(time.Duration(5) * time.Second)
	md.Reg_OnRspQrySettlementInfoTradeGo()
	md.ReqSettlementInfoGo()
	fmt.Println("#######")
	time.Sleep(time.Duration(2) * time.Second)
	quit := make(chan os.Signal)
	signal.Notify(quit, os.Interrupt)
	fmt.Println("按Ctrl+C可退出程序")
	<-quit
	fmt.Println("主程序退出")
}
